package com.cityeye.form;

import org.apache.struts.validator.ValidatorForm;

import com.cityeye.dao.DepartmentDao;
import com.cityeye.entity.Department;
import com.cityeye.entity.Loginuser;

public class DepartmentForm extends AbsEntityForm<Department> {

	// Fields

	private Integer id;
	private Integer departmentId;

	private String name;
	private String addr;

	private String phone;	
	private String comments;	
	private Integer type=3;
	
	private String manager;	
	
	// fields for filter results
	private int filterParentDepartmentId=-1;
	
	public int getFilterParentDepartmentId() {
		return filterParentDepartmentId;
	}

	public void setFilterParentDepartmentId(int filterParentDepartmentId) {
		this.filterParentDepartmentId = filterParentDepartmentId;
	}

	public String getManager() {
		return manager;
	}

	public void setManager(String manager) {
		this.manager = manager;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	// Property accessors

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getDepartmentId() {
		return this.departmentId;
	}

	public void setDepartmentId(Integer department) {
		this.departmentId = department;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddr() {
		return this.addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	public Integer getType() {
		return this.type;
	}

	public void setType(Integer type) {
		this.type = type;
	}
	
	public Department toEntity(){
		Department dept = new Department();
		dept.setId(getId());
		dept.setName(getName());		
		dept.setAddr(getAddr());
		dept.setPhone(getPhone());	
		dept.setManager(getManager());
		dept.setComments(getComments());		
		dept.setType(getType());
		
		Department parent_dept=null;
		if(getDepartmentId()!=null){
			DepartmentDao deptDao = new DepartmentDao();		
			parent_dept = deptDao.findById(getDepartmentId());
		}
		
		dept.setDepartment(parent_dept);		
		
		return dept;
	}	
}
